﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace jmwqz
{
    public partial class useredit : System.Web.UI.Page
    {
        private int id = 0;
        private Maticsoft.Model.tb_userdata muser = null;
        private Maticsoft.BLL.tb_userdata buser = new Maticsoft.BLL.tb_userdata();
        protected void Page_Load(object sender, EventArgs e)
        {
            id = Maticsoft.Common.MXRequest.GetQueryInt("id");
            if (!IsPostBack)
            {  
                muser = buser.GetModel(id);
                UpdateUI();
            }
        }
        private void UpdateUI()
        {
            if (muser != null)
            {
                txjifen.Text = muser.jifen.ToString();
                txtjnum.Text = muser.tj_num.ToString();
                this.txfreezejifen.Text = muser.freezejifen.ToString();
                this.lblRegTime.Text = muser.gz_time.ToString();
            }
        }
        //保存
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (!DoEdit(this.id))
            {
                JscriptMsg("保存过程中发生错误！", "", "Error");
                return;
            }
            JscriptMsg("修改用户成功！", "userlist.aspx", "Success");
        }

        private bool DoEdit(int id)
        {
            try
            {
                Maticsoft.Model.tb_userdata muser = buser.GetModel(id);
                if (muser != null)
                {
                    muser.tj_num = Convert.ToInt32(txtjnum.Text.Trim());
                    muser.freezejifen = Convert.ToDecimal(txfreezejifen.Text.Trim());
                    muser.jifen = Convert.ToDecimal(txjifen.Text.Trim());
                    if (buser.Update(muser))
                    {
                        return true;
                    }
                    
                }
            }
            catch (System.Exception ex)
            {
            	
            }

            return false;
        }
        protected void JscriptMsg(string msgtitle, string url, string msgcss)
        {
            string msbox = "parent.jsprint(\"" + msgtitle + "\", \"" + url + "\", \"" + msgcss + "\")";
            ClientScript.RegisterClientScriptBlock(Page.GetType(), "JsPrint", msbox, true);
        }
    }
}